import { BaseResultType } from '#/request'
import useDealResult from '@/hooks/dealResult'
import uniRequest from '@/request'

const { dealResult, checkResult } = useDealResult()

export const shLogin = async (username: string,password:string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/shLogin?username=' + username+'&password='+password)
  return Promise.resolve(dealResult(err, result))
}
export const shtzrLogin = async (username: string,password:string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/shLogin?username=' + username+'&password='+password+'&userTypev=07')
  return Promise.resolve(dealResult(err, result))
}

export const getUserDetails = async (type='gld'): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/sh/api/getUserDetails?token=' + (type=='gld'?uni.getStorageSync('shToken'):uni.getStorageSync('shtzrToken')))
  return Promise.resolve(dealResult(err, result))
}


export const resetUserPwd = async (userId: string,newPwd:string,passWord:string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get(`/sh/api/resetUserPwd?userId=${userId}&newPwd=${newPwd}&passWord=${passWord}`)
  return Promise.resolve(dealResult(err, result))
}
